package ${basePackagePath}${tablePath}.controller; 
import org.springframework.beans.factory.annotation.Autowired;
import com.hzya.frame.web.tag.LogAnnotation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;
import com.alibaba.fastjson.JSON;
import ${basePackagePath}utils.core.action.DefaultController;
import ${basePackagePath}utils.core.entity.JsonResultEntity;
import ${basePackagePath}utils.core.page.PageInfo;
import ${basePackagePath}${tablePath}.entity.${entityName};
import ${basePackagePath}${tablePath}.service.I${className}Service;
 
/**
 * @description: ${remarks}  controller
 * @tableName: ${tableName} 
 * @entityName: ${entityName}
 * 包含：
 * 1、分页查询(queryPaged)
 * 2、index页面(goIndexPage)
 * 3、新增页面(goAddPage)
 * 4、新增信息保存(save)
 * 5、修改页面(goEditPage)
 * 6、修改信息保存(update)
 * 7、信息查看(goShowPage)
 * 8、删除信息(delete)
 * @author: gjh
 * @history: 1.0
 */
<#--查询表名的最后一个_索引-->
<#global  last_index = "${tableName?last_index_of('_')}"/>
<#--获取表名的长度-->
<#global tableNameLength = "${tableName?length}"/>

@Controller("${tableName}")
@RequestMapping("/${tableName?replace('_','/')}/${className}Controller")
public class ${className}Controller extends DefaultController {
    @Autowired
    protected I${className}Service  ${className?lower_case}Service;

    /** ${remarks}分页信息 **/
    @LogAnnotation(operateModelNm = "查询",operateFuncNm = "${remarks}",operateDescribe = "${remarks}列表")
    @RequestMapping(value = "queryPaged")
    @ResponseBody
    public PageInfo<${entityName}> queryPaged( ${entityName} entity) throws Exception {
		PageInfo<${entityName}> page =null;
		try {
		   page = ${className?lower_case}Service.queryPaged(entity);
		} catch (Exception e) {
		    e.printStackTrace();
		}
		return page;
    }

	/** 跳转到${remarks}的index页面 **/
    @RequestMapping(value = "goIndexPage", method = RequestMethod.GET)
    public ModelAndView goIndexPage() {
		ModelAndView view = new ModelAndView();
		/**这里根据实际的需要填写需要传到前台的对象**/
		//view.addObject(attributeName, attributeValue);
		/**这里是返回对应的页面路径**/
		view.setViewName("/${pagePath?replace('_','/')}/${pageName}/list");
		return view;
    }

	/** 跳转到${remarks}信息新增页面 **/
    @RequestMapping(value = "goAddPage")
    public ModelAndView goAddPage() {
		ModelAndView view = new ModelAndView();
		/**这里根据实际的需要填写需要传到前台的对象**/
		//view.addObject(attributeName, attributeValue);
		/**这里是返回对应的页面路径**/
		view.setViewName("/${pagePath?replace('_','/')}/${pageName}/add");
		return view;
    }
    
    /** ${remarks}新增信息保存 **/
    @LogAnnotation(operateModelNm = "新增",operateFuncNm = "新增${remarks}",operateDescribe = "新增${remarks}")
    @RequestMapping(value = "save", method = RequestMethod.POST)
    @ResponseBody
    public JsonResultEntity save( ${entityName} entity) {
		try {
		    ${className?lower_case}Service.save(entity);
		    return getSuccessMessageEntity("保存成功", "save");
		} catch (Exception e) {
		    logger.error("save", e);
		    e.printStackTrace();
		    return getFailureMessageEntity("保存失败！"+e.getMessage(), "save");
		}
    }
    
    /** 跳转到${remarks}信息修改页面 **/
    @RequestMapping(value = "edit/{id}")
    public ModelAndView goEditPage(@PathVariable("id") Long id) {
		ModelAndView view = new ModelAndView();
		/**这里根据实际的需要填写需要传到前台的对象**/
		${entityName} entity = ${className?lower_case}Service.get(id);
		view.addObject("entity", entity);
		/**这里是返回对应的页面路径**/
		view.setViewName("/${pagePath?replace('_','/')}/${pageName}/edit");
		return view;
    }
    
    /** ${remarks}修改信息保存 **/
    @LogAnnotation(operateModelNm = "修改",operateFuncNm = "修改${remarks}",operateDescribe = "修改${remarks}")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    @ResponseBody
    public JsonResultEntity update( ${entityName} entity) {
		try {
		    ${className?lower_case}Service.update(entity);
		    return getSuccessMessageEntity("更新成功！", "update");
		} catch (Exception e) {
		    logger.error("update", e);
		    e.printStackTrace();
		    return getFailureMessageEntity("更新失败！"+e.getMessage(), "update");
		}
    }
    
    /** 跳转到${remarks}信息查看 **/
    @RequestMapping(value = "show/{id}")
    public ModelAndView goShowPage(@PathVariable("id") Long id) {
		ModelAndView view = new ModelAndView();
		/**这里根据实际的需要填写需要传到前台的对象**/
		${entityName} entity = ${className?lower_case}Service.get(id);
		view.addObject("entity", entity);
		/**这里是返回对应的页面路径**/
		view.setViewName("/${pagePath?replace('_','/')}/${pageName}/show");
		return view;
    }

	/** 删除${remarks}信息 **/
    @LogAnnotation(operateModelNm = "删除",operateFuncNm = "删除${remarks}",operateDescribe = "删除${remarks}")
    @RequestMapping(value = "delete", method = RequestMethod.POST)
    @ResponseBody
    public JsonResultEntity delete(Long id) {
		try {
		    ${className?lower_case}Service.logicRemove(id);
		    return getSuccessMessageEntity("删除成功！", "delete");
		} catch (Exception e) {
		    logger.error("delete", e);
		    e.printStackTrace();
		    return getFailureMessageEntity("删除失败！"+e.getMessage(), "delete");
		}
    }
}

